package com.luu.game.controller;

import com.luu.game.data.dto.CombotInfoDTO;
import com.luu.game.data.dto.ElfInfoDTO;
import com.luu.game.data.dto.Result;
import com.luu.game.service.BattleService;
import com.luu.game.service.RobotService;
import com.luu.game.service.UserElfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 战斗控制器
 */

@RestController
@RequestMapping("/battle")
public class BattleController {

    @Autowired
    private BattleService battleService;
    @Autowired
    private UserElfService userElfService;
    @Autowired
    private RobotService robotService;

    @PostMapping("/{id}/{skill_id}")
    public Result atcBattle(@PathVariable Integer id, @PathVariable Integer skill_id, @RequestBody ElfInfoDTO defendInfo){
        ElfInfoDTO atcElfInfo = userElfService.findById(id);
        atcElfInfo.setSkillId(skill_id);
        // ElfInfoDTO defendInfo = new ElfInfoDTO();
        // defendInfo.setHp(10d);
        // defendInfo.setAtk(10d);
        // defendInfo.setDefense(10d);
        // defendInfo.setProperty("2");

        final CombotInfoDTO combotInfoDTO = battleService.elfAtc(atcElfInfo, defendInfo);
        return new Result<CombotInfoDTO>(true, 200, "ok", combotInfoDTO);
    }

    @GetMapping("/robot/{level}/{region_id}")
    public Result createRobot(@PathVariable Integer level, @PathVariable Integer region_id){
        ElfInfoDTO robot = robotService.createRobot(level, region_id);
        return new Result<ElfInfoDTO>(true, 200, "ok", robot);
    }

}
